package com.cy.store.service.impl;

import com.cy.store.entity.Product;
import com.cy.store.mapper.ProductMapper;
import com.cy.store.service.IProductService;
import com.cy.store.service.ex.ProductNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductServiceImpl implements IProductService {

    @Autowired
    private ProductMapper productMapper;


    @Override
    public List<Product> findHotList() {
        List<Product> list = productMapper.findHotList();
        for (Product p : list){
            p.setPriority(null);
            p.setCreatedTime(null);
            p.setCreatedUser(null);
            p.setModifiedTime(null);
            p.setModifiedUser(null);
        }
        return list;
    }

    @Override
    public Product findById(Integer id) {
        Product p = productMapper.findById(id);
        if (p==null){
            throw new ProductNotFoundException("商品未找到");
        }
        p.setPriority(null);
        p.setCreatedTime(null);
        p.setCreatedUser(null);
        p.setModifiedTime(null);
        p.setModifiedUser(null);
        return  p;
    }

    @Override
    public List<Product> findAllList() {
        List<Product> list = productMapper.findAllList();
        for (Product p : list){
            p.setPriority(null);
            p.setCreatedTime(null);
            p.setCreatedUser(null);
            p.setModifiedTime(null);
            p.setModifiedUser(null);
        }
        return list;
    }
}
